package com.joesem.sale.client.logic.mine

import android.os.Bundle
import com.jiaxing.sale.client.databinding.ActivityPersonalBinding
import com.jiaxing.sale.client.databinding.LayoutToolbarBinding
import com.joesem.sale.client.base.BaseActivity
import com.joesem.sale.client.base.createViewModel
import com.joesem.sale.client.base.visible


class PersonalActivity : BaseActivity<ActivityPersonalBinding>() {

    private val viewModel by createViewModel<MineViewModel>()

    override fun LayoutToolbarBinding.toolbar(savedInstanceState: Bundle?) {
        visible()
        toolbarTheme()
        toolbarTitle.text = "用户设置"
    }

    override fun ActivityPersonalBinding.initView(savedInstanceState: Bundle?) {
        srfRefresh.isRefreshing = true
        viewModel.getUserAccount()
    }

    override fun ActivityPersonalBinding.initListener() {
        srfRefresh.setOnRefreshListener {
            viewModel.getUserAccount()
        }
    }

    override fun ActivityPersonalBinding.initIntent(intent: Any?) {
        when (intent) {
            is MineViewModel.AccountIntent -> {
                srfRefresh.isRefreshing = false
                intent.data?.let {
                    tvDeptName.text = it.dept_name.orEmpty()
                    tvNickname.text = it.realname.orEmpty()
                    tvSex.text = if (it.gender == 1) "男" else "女"
                    tvContact.text = if (it.mobile.isNullOrEmpty()) "无" else it.mobile
                    tvEmail.text = if (it.email.isNullOrEmpty()) "无" else it.email
                    tvAddressDetails.text = if (it.address.isNullOrEmpty()) "无" else it.address
                    tvBrief.text = if (it.intro.isNullOrEmpty()) "无" else it.intro
                }
            }
        }
    }
}